import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true,
  },

  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true,
  },

  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        component: () => import("@/views/dashboard/index"),
        meta: { title: "首页", icon: "dashboard" },
      },
    ],
  },
];

export const asyncRoutes = [
  // 学员授权的路由
  // {
  //   path: "/exam",
  //   component: Layout,
  //   children: [
  //     {
  //       path: "startExam",
  //       component: () => import("@/views/test/startExam"),
  //       name: "Exam",
  //       meta: {
  //         title: "随堂测验",
  //         icon: "el-icon-s-help",
  //         roles: ["student"],
  //       },
  //     },
  //   ],
  // },
  //学员和教师都授权的路由
  // {
  //   path: "/test/test",
  //   component: () => import("@/views/test/test"),
  //   name: "Test",
  //   hidden: true,
  //   meta: {
  //     title: "开始考试",
  //     icon: "el-icon-s-help",
  //     roles: ["student", "teacher"],
  //   },
  // },

  // {
  //   path: "/learn",
  //   component: Layout,
  //   redirect: "/learn/index",
  //   meta: { title: "随堂练习", icon: "table", roles: ["teacher", "student"] },
  //   children: [
  //     {
  //       path: "index",
  //       component: () => import("@/views/learn/index"),
  //       name: "Index",
  //       meta: {
  //         title: "随堂练习",
  //         icon: "el-icon-s-help",
  //       },
  //     },
  //     {
  //       path: "listening",
  //       component: () => import("@/views/learn/listen/index"),
  //       redirect: "/learn/listening/listening",
  //       name: "Listening",
  //       meta: {
  //         title: "英语听力",
  //         icon: "el-icon-s-help",
  //       },
  //       children: [
  //         {
  //           path: "listening",
  //           component: () => import("@/views/learn/listen/listening"),
  //           name: "Listening",
  //           meta: {
  //             title: "英语听力",
  //             icon: "el-icon-s-help",
  //           },
  //         },
  //         {
  //           path: "listenTest",
  //           component: () => import("@/views/learn/listen/listenTest"),
  //           name: "ListenTest",
  //           meta: {
  //             title: "听力测试",
  //             icon: "el-icon-s-help",
  //           },
  //           hidden: true,
  //         },
  //         {
  //           path: "listenText",
  //           component: () => import("@/views/learn/listen/listenText"),
  //           name: "ListenText",
  //           meta: {
  //             title: "听力原文",
  //             icon: "el-icon-s-help",
  //           },
  //           hidden: true,
  //         },
  //       ],
  //     },

  //     {
  //       path: "learn",
  //       // component: Layout,
  //       component: () => import("@/views/learn/learn"),
  //       meta: { title: "开始练习", icon: "table" },
  //       hidden: true,
  //     },
  //   ],
  // },
  {
    path: "/testResult",
    component: Layout,
    redirect: "/testResult/index",
    children: [
      {
        path: "index",
        component: () => import("@/views/test/testResult"),
        name: "TestResult",
        meta: {
          title: "查看考卷",
          icon: "table",
          roles: ["teacher"],
        },
      },
      {
        path: "testAnswer",
        name: "testAnswer",
        hidden: true,
        component: () => import("@/views/test/testAnswer"),
        meta: {
          title: "获取试卷",
          icon: "table",
          roles: ["teacher"],
        },
      },
    ],
  },
  //只有教师授权的路由
  {
    path: "/questionAdmin",
    component: Layout,
    children: [
      {
        path: "index",
        component: () => import("@/views/questionItem/admin"),
        name: "QuestionAdmin",
        meta: {
          path: "index",
          title: "考卷管理",
          icon: "el-icon-s-help",
          roles: ["teacher"],
        },
      },
    ],
  },
  {
    path: "/education",
    component: Layout,
    meta: { title: "课程管理", icon: "table", roles: ["teacher"] },
    redirect: "/education/index",
    children: [
      {
        path: "index",
        component: () => import("@/views/education/index.vue"),
        name: "education",
        meta: { title: "课程管理", icon: "el-icon-s-help" },
      },
      {
        path: "ppt",
        component: () => import("@/views/education/ppt.vue"),
        name: "ppt",
        meta: { title: "课件管理", icon: "el-icon-s-help" },
      },
      {
        path: "edit",
        component: () => import("@/views/education/edit.vue"),
        name: "edit",
        meta: { title: "课程信息", icon: "el-icon-s-help" },
        hidden: true,
      },
      {
        path: "video",
        component: () => import("@/views/education/video.vue"),
        name: "Video",
        meta: { title: "视频管理", icon: "el-icon-s-help" },
      },
      {
        path: "word",
        component: () => import("@/views/education/word.vue"),
        name: "Video",
        meta: { title: "文档管理", icon: "el-icon-s-help" },
      },
    ],
  },
  {
    path: "/test",
    component: Layout,
    meta: { title: "开始出卷", icon: "table", roles: ["teacher"] },
    children: [
      {
        path: "zhiZhao",
        component: () => import("@/views/questionItem/zhiZhao"),
        name: "ZhiZhao",
        meta: { title: "基础执照", icon: "el-icon-s-help" },
      },
      {
        path: "da42",
        name: "Da42",
        component: () => import("@/views/questionItem/da42"),
        meta: { title: "42全程班", icon: "table" },
      },
      {
        path: "da42Sup",
        name: "Da42Sup",
        component: () => import("@/views/questionItem/da42Sup"),
        meta: { title: "TEA补差E4", icon: "table" },
      },
    ],
  },
  //管理员和教师都授权的路由
  {
    path: "/user",
    component: Layout,
    meta: { title: "用户管理", icon: "table", roles: ["admin", "teacher"] },
    redirect: "/user/admin",
    children: [
      {
        path: "admin",
        component: () => import("@/views/user/admin"),
        name: "admin",
        meta: {
          title: "用户管理",
          icon: "el-icon-s-help",
        },
      },
      {
        path: "class",
        component: () => import("@/views/user/class"),
        name: "Class",
        meta: {
          title: "班级管理",
          icon: "el-icon-s-help",
        },
      },
      {
        path: "statistcs",
        component: () => import("@/views/user/statistics"),
        name: "Statistcs",
        hidden: true,
        meta: {
          title: "数据统计",
          icon: "el-icon-s-help",
        },
      },
    ],
  },
  //管理员授权的路由
  {
    path: "/question",
    component: Layout,
    meta: { title: "题目管理", icon: "table", roles: ["admin", "teacher"] },
    redirect: "/question/admin",
    children: [
      {
        path: "admin",
        component: () => import("@/views/question/admin"),
        name: "Admin",
        meta: { title: "题目管理", icon: "el-icon-s-help" },
      },
      {
        path: "specialCare",
        component: () => import("@/views/question/specialCare"),
        name: "SpecialCare",
        meta: { title: "特别关注点", icon: "el-icon-s-help" },
      },
      {
        path: "listen_admin",
        component: () => import("@/views/question/listenAdmin"),
        name: "listen_Admin",
        meta: { title: "音频资源", icon: "el-icon-s-help" },
      },
      {
        path: "feedback",
        component: () => import("@/views/question/feedback"),
        name: "feedback",
        meta: { title: "反馈错题", icon: "el-icon-s-help" },
      },
    ],
  },

  // 404 page must be placed at the end !!!
  { path: "*", redirect: "/404", hidden: true },
];

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    mode: "hash",
    routes: constantRoutes,
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
